import { Inject, Provide } from "@midwayjs/core";
import { InjectEntityModel } from "@midwayjs/typeorm";
import { Repository } from "typeorm";
import { TenantInfoEntity } from "../entity/info";
import { BaseService } from "@cool-midway/core";
import { Context } from "@midwayjs/koa";

@Provide()
export class TenantInfoService extends BaseService {
    @InjectEntityModel(TenantInfoEntity)
    tenantInfoEntity: Repository<TenantInfoEntity>

    @Inject()
    ctx: Context

    // 根据团队ID获取租户信息
    async getTenantInfoByTeamId(teamId: number) {
        return this.tenantInfoEntity.findOne({
            where: { teamId },
        });
    }

    // 创建租户信息
    async createTenantInfo(teamId: number) {
        // 更新服务人员信息表的isTenant为true

        // 创建租户信息

        // 更新服务人员信息表的tenantId为租户信息表的id

        // 更新服务人员登录jwt token
        return await this.tenantInfoEntity.save({
            teamId,
        });
    }
}